﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class webadmin_pages_sanvieclam_list : System.Web.UI.Page
{
    public Common _common;
    public static string _ma_vetinh = "";
    public DataTable catdtt;
    public DataTable catsubdtt;
    public DataTable newsddt = new DataTable();
    protected void btn_del_vetinh_Click(object sender, EventArgs e)
    {
        if (this._common.execNoneQuery("delete TrungTamViecLam where ma_trung_tam = " + _ma_vetinh) > 0)
        {
            this._common.execNoneQuery("delete SanGiaoDich where ma_trung_tam = " + _ma_vetinh);
            base.Response.Redirect("sanvieclam_list.aspx");
        }
    }

    private void LoadSanvieclam(string ma_san)
    {
        string sql = "select *, convert(varchar, A.ngay_tao, 103) as ngaytao_vn, convert(varchar, A.ngay_dien_ra, 103) as ngaydienra_vn  from SanGiaoDich as A where A.ma_trung_tam = " + ma_san;
        DataSet set = this._common.ExeceuteDataset(sql);
        this.rpt_kdt.DataSource = set;
        this.rpt_kdt.DataBind();
        this.lbl_total.Text = set.Tables[0].Rows.Count.ToString();
    }

    protected void LoadTree()
    {
        this._tree.Nodes.Clear();
        TreeNode child = new TreeNode("Danh s\x00e1ch c\x00e1c vệ tinh", "0");
        this.catdtt = this._common.getDataTable("Select * from dbo.TrungTamViecLam where ve_tinh = '1'");
        for (int i = 0; i < this.catdtt.Rows.Count; i++)
        {
            if (i == 0)
            {
                this.LoadSanvieclam(this.catdtt.Rows[i]["ma_trung_tam"].ToString());
                _ma_vetinh = this.catdtt.Rows[i]["ma_trung_tam"].ToString();
            }
            TreeNode node2 = new TreeNode(" " + this.catdtt.Rows[i]["ten_trung_tam"].ToString(), this.catdtt.Rows[i]["ma_trung_tam"].ToString());
            child.ChildNodes.Add(node2);
        }
        this._tree.Nodes.Add(child);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this._common = new Common();
        if ((!string.IsNullOrEmpty(base.Request.Params["id"]) && !string.IsNullOrEmpty(base.Request.Params["act"])) && base.Request.Params["act"].ToString().Trim().Equals("del"))
        {
            string str = this._common.TextFormat(base.Request.Params["id"].ToString());
            this._common.execNoneQuery("delete SanGiaoDich where ma_san = '" + str + "'" + "");
            this._common.execNoneQuery("delete SanGiaoDich_doanh_nghiep where ma_san = '" + str + "'" + "");
            base.Response.Redirect("sanvieclam_list.aspx");
        }
        if (!this.Page.IsPostBack)
        {
            this.LoadTree();
        }
        else
        {
            this.LoadSanvieclam(this._tree.SelectedNode.Value);
            _ma_vetinh = this._tree.SelectedNode.Value;
        }
    }
}
